package lab5;

import java.util.Date;

class Rectangle{
	private double width,height;
	Rectangle(double newwidth,double newheight)
	{
		 width = newwidth;
		 height = newheight;
	}
	public double getArea()
	{
		return width*height;
	}
	public double getPerimeter()
	{
		return 2*(width+height);
	}
}

class Stock{
	private String symbol,name;
	private double previousClosingPrice,currentPrice;
	  Stock(String newSymbol,String newName){
	        this.name = newName;
	        this.symbol = newSymbol;
	    }
	  public String getChangePercent(double preciousClosingPrice,double currentPrice){
	        return (currentPrice - preciousClosingPrice) / (preciousClosingPrice * 100) + "%";
	    }

	  
}

class Stopwatch{
	private long startTime;
    private long endTime;
    public void setStartTime(long newStartTime){
        startTime = newStartTime;
    }
    public void setEndTime(long newEndTime){
        endTime = newEndTime;
    }
    public Stopwatch(){
        startTime = System.currentTimeMillis();
    }

    public void start(){
        startTime = System.currentTimeMillis();
    }

    public void stop(){
        endTime = System.currentTimeMillis();
    }

    public long getElapsedTime(){
        return endTime - startTime;
    }
}

class Account{
    private int id;
    private double balance;
    private double annualInterestRate;
    private Date dateCreated;

    public Account(){
        dateCreated = new Date();
        id = 0;
        balance = 0;
        annualInterestRate = 0;
    }

    public Account(int ID, double BALANCE){
        dateCreated = new Date();
        id = ID;
        balance = BALANCE;
        annualInterestRate = 0.045;
    }

    public int getId(){
        return id;
    }

    public void setId(int ID){
        id = ID;
    }

    public double getBalance(){
        return balance;
    }

    public void setBalance(double ba){
        balance = ba;
    }

    public double getAnnualInterestRate(){
        return annualInterestRate;
    }

    public void setAnnualInterestRate(double annual){
        annualInterestRate = annual;
    }

    public Date getDate(){
        return dateCreated;
    }

    public double getMonthlyInterestRate(){
        return annualInterestRate / 12.0;
    }

    public boolean withDraw(double money){
        if(balance >= money){
            balance -= money;
            return true;
        }
        else
            return false;
    }

    public boolean deposit(double money){
        if(money >= 0){
            balance += money;
            return true;
        }
        else
            return false;
    }
}

public class Lab5Main {
    public static void main(String[] args){
    	Rectangle myRectangle1 = new Rectangle(4,40);
    	System.out.println(myRectangle1.getArea());
    	System.out.println(myRectangle1.getPerimeter());
    	Rectangle myRectangle2 = new Rectangle(3.5,35.9);
    	System.out.println(myRectangle2.getArea());
    	System.out.println(myRectangle2.getPerimeter());
    	Stock myStock = new Stock("ORCL","Oracle Corporation");
    	System.out.println(myStock.getChangePercent(34.5,34.35));
    	Stopwatch time = new Stopwatch();
        int[] nums = new int[100000];
        for(int i = 1; i <= 100000; ++i)
            nums[i - 1] = (int)((System.currentTimeMillis() / i) % 1000);

        time.start();
        for(int i = 0; i < 99999; ++i){
            for(int j = i+1; j < 100000; ++j){
                if(nums[i] > nums[j]){
                    int temp = nums[i];
                    nums[i] = nums[j];
                    nums[j] = temp;
                }
            }
        }
        time.stop();
        System.out.println(time.getElapsedTime());
        Account account = new Account(1122,20000);
        if(account.withDraw(2500))
            System.out.println("Success");
        else
            System.out.println("Fail");

        if(account.deposit(2500))
            System.out.println("Success");
        else
            System.out.println("Fail");

        System.out.println("balance:" + account.getBalance());
        System.out.println("monthly interest:" + account.getMonthlyInterestRate() * account.getBalance());
        System.out.println(account.getDate().toString());
    }
}